/*
 * Player.cpp
 *
 *  Created on: 2011/05/28
 *      Author: naoki
 */

#include "Stdafx.h"
#include "Sound/src/ManagerImpl.h"
#include "Sound/src/PlayerImpl.h"

namespace NTEngine {
namespace Sound {

const int Player::LOOP_NONE = 0;
const int Player::LOOP_INFINITY = -1;

Player Player::create( Wave bank ) {
	HARD_ASSERT( bank.isReady() && !bank.isError() );
	Player ret;
	ret.mImpl = NEW Impl( bank.mImpl, gManagerImpl->mEngine, gManagerImpl->mOutputMix );
	return ret;
}

void Player::play() {
	ASSERT( mImpl );
	mImpl->play();
}

void Player::pause() {
	ASSERT( mImpl );
	mImpl->pause();
}

void Player::stop() {
	ASSERT( mImpl );
	mImpl->stop();
}

void Player::setLoop( int v ) {
	ASSERT( mImpl );
	ASSERT( !mImpl->isPlaying() ); // 再生中でなければ設定できる
	if ( v < LOOP_INFINITY ) {
		v = LOOP_INFINITY;
	}
	mImpl->mLoopCount = v;
}

bool Player::isLoop() const {
	ASSERT( mImpl );
	return( mImpl->mLoopCount != LOOP_NONE );
}

bool Player::isPlaying() const {
	ASSERT( mImpl );
	return mImpl->isPlaying();
}

void Player::setVolume( int v ) {
	ASSERT( mImpl );
	mImpl->setVolume( v );
}

int Player::volume() const {
	ASSERT( mImpl );
	return mImpl->volume();
}

void Player::setPitch( float v ) {
	ASSERT( mImpl );
	mImpl->setPitch( v );
}

float Player::pitch() const {
	ASSERT( mImpl );
	return mImpl->pitch();
}

#define TYPE Player
#include "NTEngine/Base/Impl/ReferenceCounterTemplate.h"

} // namespace Sound
} // namespace NTEngine
